package com.laotou99.wmsjjj.wmsjjj.service;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.laotou99.wmsjjj.wmsjjj.bean.po.LOTPO;
import com.laotou99.wmsjjj.wmsjjj.bean.vo.COUNTLOTVO;
import com.laotou99.wmsjjj.wmsjjj.repository.LOTPORepository;

@Service
public class LOTService {

	@Autowired
	LOTPORepository lotpoRepository;
	
	//显示批次属性
	public String showAllLot() { 
		List<LOTPO> list = lotpoRepository.findAll(); 
		return JSONObject.toJSONString(list);
	}

	//显示此物料下仓库存货数量
	public List<COUNTLOTVO> CountNumAllSku() {
		
		List<COUNTLOTVO> li1 = new ArrayList<COUNTLOTVO>();
		
//		COUNTLOTVO clotvo = new COUNTLOTVO();
		List<Object[]> list = lotpoRepository.CountSku();
		System.out.println("list-=>"+JSON.toJSONString(list));
//		clotvo.setSku(sku);
		for(Object[] a:list) {
			COUNTLOTVO clotvo = new COUNTLOTVO();
			//["0001","apple",100,"iPad 32G","iPad 32G"]
			clotvo.setSku(""+a[0]);
			clotvo.setStoreKey(""+a[1]);
			clotvo.setMoqNum(((BigInteger)a[2]).intValue());
			clotvo.setSkucn(""+a[3]);
			clotvo.setSkuen(""+a[4]);
			li1.add(clotvo);
		} 
		return li1;
	}
/*
SELECT t.SKU,t.STORE_KEY,SUM(t.MOQ_NUM) AS NUM,
o.SKUEN,o.SKUCN 
FROM LOTPO t,SKUPO o
WHERE t.SKU = o.SKU_ID
GROUP BY t.SKU,t.STORE_KEY,o.SKUEN,o.SKUCN
 * */	
}
